
<?php

class ThemesForm extends PostBackControl {
	var $ConfigurationManager;

	function ThemesForm(&$Context) {
		$this->Name = 'ThemesForm';
		$this->ValidActions = array('Themes', 'ProcessThemes');
		$this->Constructor($Context);
		if( $this->IsPostBack ) {
			$RedirectUrl = '';
			$this->Context->PageTitle = $this->Context->GetDefinition('VcalThemesManagement');

			$SettingsFile = $this->Context->Configuration['APPLICATION_PATH'].'conf/settings.php';
			$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
			if ($this->PostBackAction == 'ProcessThemes') {
				$this->ConfigurationManager->GetSettingsFromForm($SettingsFile);
				$this->ConfigurationManager->DefineSetting('VCAL_DEFAULT_THEME', ForceIncomingString('VCAL_DEFAULT_THEME', ''), '');
				if ($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) {
					$RedirectUrl = GetUrl(
							$this->Context->Configuration, $this->Context->SelfUrl, '', '', '', '',
							'PostBackAction=Themes&Success=1');
				} else {
					$this->PostBackAction = 'Themes';
				}
			}
			if ($RedirectUrl) {
				//@todo: should the process die here?
				Redirect($RedirectUrl, '302', '', 0);
			}
		}
		
		$this->CallDelegate('Constructor');
	}
	function GetChecked ($Theme) {
		if ($this->ConfigurationManager->GetSetting('VCAL_DEFAULT_THEME') == $Theme) return 'checked="checked"';

	}
	function GetEnabled ($Theme) {
		if ($this->ConfigurationManager->GetSetting('VCAL_DEFAULT_THEME') == $Theme) return 'class="Enabled"';
		else return 'class="Disabled"';
	}

	function Render() {
		if ($this->IsPostBack) {
			$this->CallDelegate('PreRender');
			$this->PostBackParams->Clear();
			if ($this->PostBackAction == 'Themes') {
				$this->PostBackParams->Set('PostBackAction', 'ProcessThemes');

				echo '
				<div id="Form" class="Account ThemesSettings">';
				if (ForceIncomingInt('Success', 0)) echo '<div id="Success">'.$this->Context->GetDefinition('VcalChangesSaved').'</div>';
				echo '
					<fieldset>
						<legend>'.$this->Context->GetDefinition("VcalThemesSettings").'</legend>
						'.$this->Get_Warnings().'
						'.$this->Get_PostBackForm('frmThemes').'
						<p>'.$this->Context->GetDefinition("VcalThemesNotes").'</p>
						<ul id="ThemeList">
							<li '.$this->GetEnabled("Vcal").'>
								<p><input type="radio" class="form-radio" '.$this->GetChecked("Vcal").'" value="Vcal" name="VCAL_DEFAULT_THEME"/><span><strong>'.$this->Context->GetDefinition('VcalThemesVcal').'</strong></span></p>
								<p class="description">Table-based multi-column theme with a marine and ash color scheme.</p>
								<p class="image"><img class="screenshot" title="" alt="Screenshot for <em>Bluemarine</em> theme" src="./extensions/Vcal/theme/screenshot.png"/></p>
							</li>
							<li '.$this->GetEnabled("Google").'>
								<p><input type="radio" class="form-radio" '.$this->GetChecked("Google").'" value="Google" name="VCAL_DEFAULT_THEME"/><span><strong>'.$this->Context->GetDefinition('VcalThemesGoogle').'</strong></span></p>
								<p class="description">Table-based multi-column theme with a marine and ash color scheme.</p>
								<p class="image"><img class="screenshot" title="" alt="Screenshot for <em>Bluemarine</em> theme" src="./extensions/Vcal/theme/screenshot-1.png"/></p>
							</li>
							<li '.$this->GetEnabled("OSX Gray").'>
								<p><input type="radio" class="form-radio" '.$this->GetChecked("OSX Gray").'" value="OSX Gray" name="VCAL_DEFAULT_THEME"/><span><strong>'.$this->Context->GetDefinition('VcalThemesOSXGray').'</strong></span></p>
								<p class="description">Table-based multi-column theme with a marine and ash color scheme.</p>
								<p class="image"><img class="screenshot" title="" alt="Screenshot for <em>Bluemarine</em> theme" src="./extensions/Vcal/theme/screenshot-2.png"/></p>
							</li>
				

						</ul>
						<br />
						<div class="Submit">
							<input type="submit" name="btnSave" value="'.$this->Context->GetDefinition('Save').'" class="Button SubmitButton" />
							<a href="'.GetUrl($this->Context->Configuration, $this->Context->SelfUrl).'" class="CancelButton">'.$this->Context->GetDefinition('Cancel').'</a>
						</div>
						</form>
					</fieldset>
				</div>
				';
			}
			$this->CallDelegate('PostRender');
		}
	}
}
?>